home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MEMORY.SWG / 0022_Checking for Cache.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  5KB  |  270 lines

  1. {
  2. FRANCOIS THUNUS
  3.  
  4. > Would it be possible to throw a [Ctrl-Alt-Del] into the keyboard buffer,
  5. > causing Smartdrv to Write its data and warm boot the computer? if so, any
  6. > ideal how a person would do this?
  7.  
  8. trap keyboard info
  9. if ctr-alt-del then begin
  10.             check For smrtdrv
  11.             if smrtdrv then flush cache
  12.             reboot
  13.             end;
  14.  
  15. Flush cache: (was posted here but since it is more than a month old, i guess
  16. it's ok to repost ?):
  17. }
  18.  
  19. Unit SfeCache;
  20. {
  21.  
  22. Max Maischein                                  Sunday,  7.03.1993
  23. 2:249/6.17                                         Frankfurt, GER
  24.  
  25. This  Unit  implements   an   automatic   flush   For   installed
  26. Write-behind caches like SmartDrive and PC-Cache. It's  based  on
  27. cache detection code by Norbert Igl, I added the calls  to  flush
  28. the buffers. The stuff is only tested For SMARTDRV.EXE, the  rest
  29. relies on Norbert and the INTERRUP.LST from Ralf Brown.
  30.  
  31. Al says : "Save early, save often !"
  32.  
  33. The Unit exports one  Procedure,  FlushCache,  this  flushes  the
  34. first cache found. It  could  be  good  to  flush  everything  on
  35. Program termination, since users are likely to switch  off  their
  36. computers directly upon Exit from the Program.
  37.  
  38. This piece of code is donated to the public domain, but I request
  39. that, if you use this code, you mention me in the DOCs somewhere.
  40.                                                            -max
  41. }
  42. Interface
  43.  
  44. Implementation
  45.  
  46. Uses
  47.   Dos;
  48.  
  49. Const
  50.   AktCache : Byte = 0;
  51.  
  52. Type
  53.   FlushProc = Procedure;
  54.  
  55. Var
  56.   FlushCache : FlushProc;
  57.  
  58. Function SmartDrv_exe : Boolean;
  59. Var
  60.   Found : Boolean;
  61. begin
  62.   Found := False;
  63.   Asm
  64.     push    bp
  65.     stc
  66.     mov     ax, 4A10h
  67.     xor     bx, bx
  68.     int     2Fh
  69.     pop     bp
  70.     jc      @NoSmartDrive
  71.     cmp     ax, 0BABEh
  72.     jne     @NoSmartDrive
  73.     mov     Found, True
  74.    @NoSmartDrive:
  75.   end;
  76.   SmartDrv_exe := Found;
  77. end;
  78.  
  79. Function SmartDrv_sys : Boolean;
  80. Var
  81.   F  : File;
  82.   B  : Array[0..$27] of Byte; { return Buffer }
  83.   OK : Boolean;
  84. Const
  85.   S = SizeOf( B );
  86. begin
  87.   SmartDrv_sys := False;
  88.   OK := False;
  89.   { -------Check For SmartDrv.SYS----------- }
  90.   Assign(f,'SMARTAAR');
  91.   {$I-}
  92.   Reset( F );
  93.   {$I+}
  94.   if IoResult <> 0 then
  95.     Exit; { No SmartDrv }
  96.   FillChar( B, Sizeof(B), 0 );
  97.   Asm
  98.     push    ds
  99.     mov     ax, 4402h
  100.     mov     bx, TextRec( F ).Handle
  101.     mov     cx, S
  102.     mov     dx, seg B
  103.     mov     ds, dx
  104.     mov     dx, offset B
  105.     int     21h
  106.     jc      @Error
  107.     mov     OK, 1
  108.    @Error:
  109.     pop     ds
  110.   end;
  111.   close(f);
  112.   SmartDrv_sys := OK;
  113. end;
  114.  
  115. Function CompaqPro : Boolean;
  116. Var
  117.   OK : Boolean;
  118. begin
  119.   CompaqPro := False;
  120.   OK := False;
  121.   Asm
  122.     mov     ax, 0F400h
  123.     int     16h
  124.     cmp     ah, 0E2h
  125.     jne     @NoCache
  126.     or      al, al
  127.     je      @NoCache
  128.     cmp     al, 2
  129.     ja      @NoCache
  130.     mov     OK, 1
  131.    @NoCache:
  132.   end;
  133.   CompaqPro := OK;
  134. end;
  135.  
  136. Function PC6 : Boolean;   { PCTools v6, v5 }
  137. Var
  138.   OK : Boolean;
  139. begin
  140.   PC6 := False;
  141.   OK := False;
  142.   Asm
  143.     mov     ax, 0FFA5h
  144.     mov     cx, 01111h
  145.     int     16h
  146.     or      ch, ch
  147.     jne     @NoCache
  148.     mov     OK, 1
  149.    @NoCache:
  150.   end;
  151.   PC6 := OK;
  152. end;
  153.  
  154. Function PC5 : Boolean;
  155. Var
  156.   OK : Boolean;
  157. begin
  158.   PC5 := False;
  159.   OK := False;
  160.   Asm
  161.     mov     ax, 02BFFh
  162.     mov     cx, 'CX';
  163.     int     21h
  164.     or      al, al
  165.     jne     @NoCache
  166.     mov     ok, 1
  167.    @NoCache:
  168.   end;
  169.   PC5 := OK;
  170. end;
  171.  
  172. Function HyperDsk : Boolean;   { 4.20+ ... }
  173. Var
  174.   OK : Boolean;
  175. begin
  176.   Hyperdsk := False;
  177.   OK := False;
  178.   Asm
  179.     mov     ax, 0DF00h
  180.     mov     bx, 'DH'
  181.     int     02Fh
  182.     cmp     al, 0FFh
  183.     jne     @NoCache
  184.     cmp     cx, 05948h
  185.     jne     @NoCache
  186.     mov     OK, 1
  187.    @NoCache:
  188.   end;
  189.   HyperDSK := OK;
  190. end;
  191.  
  192. Function QCache : Boolean;
  193. Var
  194.   OK : Boolean;
  195. begin
  196.   QCache := False;
  197.   OK := False;
  198.   Asm
  199.     mov     ah, 027h
  200.     xor     bx, bx
  201.     int     013h
  202.     or      bx, bx
  203.     je      @NoCache
  204.     mov     OK, 1
  205.    @NoCache:
  206.   end;
  207.   QCache := OK;
  208. end;
  209.  
  210. Procedure FlushSD_sys; Far;
  211. Var
  212.   F : File;
  213.   B : Byte;
  214. begin
  215.   Assign(F, 'SMARTAAR');
  216.   Reset(F);
  217.   B := 0;
  218.   Asm
  219.     push    ds
  220.     mov     ax, 04403h
  221.     mov     bx, FileRec(F).Handle
  222.     mov     cx, 1
  223.     int     21h
  224.     pop     ds
  225.   end;
  226. end;
  227.  
  228. Procedure FlushSD_exe; Far; Assembler;
  229. Asm
  230.   mov     ax, 04A10h
  231.   mov     bx, 1
  232.   int     2Fh
  233. end;
  234.  
  235. Procedure FlushPC6; Far; Assembler;
  236. Asm
  237.   mov     ax, 0F5A5h
  238.   mov     cx, -1
  239.   int     16h
  240. end;
  241.  
  242. Procedure FlushPC5; Far; Assembler;
  243. Asm
  244.   mov     ah, 0A1h
  245.   mov     si, 04358h
  246.   int     13h
  247. end;
  248.  
  249. Procedure FlushNoCache; Far;
  250. begin
  251. end;
  252.  
  253. begin
  254.   if SmartDrv_exe then
  255.     FlushCache := FlushSD_exe
  256.   else
  257.   if SmartDrv_sys then
  258.     FlushCache := FlushSD_sys
  259.   else
  260.   if PC6 then
  261.     FlushCache := FlushPC6
  262.   else
  263.   if PC5 then
  264.     FlushCache := FlushPC5
  265.   else
  266.     FlushCache := FlushNoCache;
  267.  
  268.   FlushCache;
  269. end.
  270.